package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.exception.BusinessRuntimeException;
import com.itheima.health.pojo.OrderSetting;
import com.itheima.health.service.OrderService;
import com.itheima.health.service.OrderSettingService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

/**
 * @author spt
 * @description 预约设置控制器
 * @date
 **/
@RestController
@RequestMapping("/ordersetting")
@Slf4j
public class OrderSettingController {

    @Autowired
    private OrderService orderService;

    /**
     * MR.zhang
     * 任务5 体检预约-日历展示预约设置信息
     *
     * @param year
     * @param month
     * @return
     */
    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMonth(@RequestParam Integer year, @RequestParam Integer month) {
        log.info("接收到预约设置的参数,{},{}", year, month);
        List<Map> orderSettings = orderService.listordersetting(year, month);
        return new Result(true, MessageConst.GET_ORDERSETTING_SUCCESS, orderSettings);
    }

    /**
     * MR.zhang
     * 任务6 体检预约-基于日历实现预约设置
     *
     * @param orderSetting
     * @return
     */
    @PostMapping("/editNumberByDate")
    public Result editNumberByDate(@RequestBody OrderSetting orderSetting) {
        log.info("接收到参数,{}", orderSetting.getOrderDate());
        orderService.updateorderstting(orderSetting);
        return new Result(true, MessageConst.ORDERSETTING_SUCCESS);
    }
    //http://localhost:18080/api/ordersetting/upload

    /**
     * MR.zhang
     * 任务4 完成预约设置-文件上传批量进行预约设置
     *
     * @return
     */
    @PostMapping("/upload")
    public Result upload( @RequestParam("excelFile") MultipartFile excelFile) {
        //???接收到数据
        log.info("文件上传批量进行预约设置接收到数据,{}", excelFile.getOriginalFilename());
        boolean b = orderService.savebatch(excelFile);
        return new Result(b, MessageConst.IMPORT_ORDERSETTING_SUCCESS);
    }
}
